package acm.pta7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

public class 小字辈2 {
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n = sc.nextInt();
        List<Integer>[] map=new List[n+1];  //图，邻接表
        for (int i = 1; i < map.length; i++) {
            map[i]=new LinkedList<>();
        }
        int root=-1;
        for (int i = 1; i <= n; i++) {  //构建图 O(N)
            int parent = sc.nextInt();
            if (parent==-1){
                root=i;
            }else {
                map[parent].add(i);
            }
        }
        Queue<Integer> queue=new LinkedList<>();
        queue.add(root);
        int currEnd=root,nextEnd=-1;
        int level=0;
        List<Integer> list=new LinkedList<>();
        while (!queue.isEmpty()){   //宽度遍历 O(N)
            Integer node = queue.poll();
            list.add(node);
            for (Integer child : map[node]) {   //把所有孩子加入
                queue.add(child);
                nextEnd=child;
            }
            if (currEnd==node){ //抵达边界
                level++;
                currEnd=nextEnd;
                if (!queue.isEmpty()){
                    list=new LinkedList<>();
                }
            }
        }
        System.out.println(level);
        StringBuilder sb=new StringBuilder();
        for (Integer t : list) {
            sb.append(t).append(" ");
        }
        System.out.println(sb.substring(0,sb.length()-1));
    }

    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }

}
